<?php

/**
 * Abstract
 * 作者: 魏炎荣
 */
class Controller_Admin_Main extends Controller_Admin_Abstract
{
    /**
     * 后台框架主体
     */
    public function indexAction()
    {
        global $_F;
        /**
         * 账务账号默认地址为结算界面
         */
        $left_url = '/admin/main/left';
        $main_url = '/admin/Order/list';
        if($_F['member']['isadmin'] == 3){
            $left_url = '/admin/main/left?menu=finacial';
            $main_url = '/admin/finacial/settlement';
        }
        $this->assign('left_url',$left_url);
        $this->assign('main_url',$main_url);
        $this->display('admin/frame/index');
    }

    /**
     * 后台框架主体，头部显示
     */
    public function topAction()
    {
        global $_F;
        $menu = FConfig::get('menu');
        $topArray = array();
        foreach ($menu as $k=>$v){
            $topArray[$k] = array('name'=>$v['name'],'url'=>'/admin/main/left?menu='.$k);
        }
        /**
         * 判断账号的角色类型，显示相应的菜单
         * 运营账号没有账务和系统功能
         */
        if($_F['member']['isadmin'] == 2){
            unset($topArray['finacial'],$topArray['system']);
        }
        /**
         * 账务账号没有系统功能
         */
        if($_F['member']['isadmin'] == 3){
            unset($topArray['system']);
        }

        $this->assign('topItems', $topArray);
        $this->display('admin/frame/top');
    }
    /**
     * 后台框架主体，左侧菜单
     */
    public function leftAction()
    {
        global $_F;
        $menu = FConfig::get('menu');
        $menuArray = array();
        foreach ($menu as $k=>$v){
            $menuArray[$k] = $v['menu'];
        }
        $menuInit = FRequest::getString('menu');
        if(!$menuInit || !isset($menuArray[$menuInit])){
            $menuInit = 'main';
        }
        /**
         * 判断账号的角色类型，显示相应的菜单
         * 运营账号没有账务和系统功能
         */
        if($_F['member']['isadmin'] == 2){
            $menuInit = 'main';
        }
        /**
         * 账务账号没有系统功能
         */
        if($_F['member']['isadmin'] == 3){
            $menuInit = $menuInit == 'system' ? 'finacial' : $menuInit;
        }

        $menuList = array();
        foreach ($menuArray[$menuInit] as $v){
            if(Service_Manager::checkRole($v['url'])){
                $menuList[] = $v;
            }
        }

        $this->assign('menuItems', $menuList);
        $this->display('admin/frame/left');
    }

    /**
     * 后台框架主体，默认显示界面
     */
    public function mainAction()
    {
        $this->display('admin/frame/main');
    }

    /**
     * 后台框架主体，左侧控制开关
     */
    public function borderAction()
    {
        $this->display('admin/frame/border');
    }

    /**
     * 后台用户修改自己的登录密码
     */
    public function editAction(){
        global $_F;
        $manager = $_F['member'];
        if($this->isPost()){
            $truename = FRequest::getPostString('truename');
            $password = FRequest::getPostString('password');
            $re_password = FRequest::getPostString('re_password');
            $data = array(
                'truename'=>$truename
            );
            if($password != ""){
                if($password != $re_password){
                    $this->error('两次密码不一致，请重新确认');
                }
                if(Service_Manager::getEncryptPassword($password) == $manager['password']){
                    $this->error('新密码与原始密码相同');
                }
                $data['password'] = Service_Manager::getEncryptPassword($password);
            }
            $managerTable = new FTable('manager');
            $managerTable->where(array('uid'=>$_F['uid']))->update($data);
            Service_Manager::clearInfoById($_F['uid']);
            $this->success('修改个人信息成功');
        }
        $this->assign('info',$manager);
        $this->display('manager/editpwd');
    }

}
